home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // ResourceSpeech.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
-
-
- //____________________________________________________________
-
- #include <Speech.h>
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void );
- Boolean IsSpeechAvailable( void );
- void OpenSpeechDialog( void );
- OSErr SpeakOneString( Str255 );
-
-
- //____________________________________________________________
-
- #define rSpeechDialog 128
- #define kSpeakShortButton 1
- #define kSpeakLongButton 2
- #define kQuitButton 3
- #define rStringList 128
- #define kShortStrIndex 1
- #define kLongStrIndex 2
-
-
- //____________________________________________________________
-
- void main( void )
- {
- Boolean speechPresent;
-
- InitializeToolbox();
-
- speechPresent = IsSpeechAvailable();
- if ( speechPresent == false )
- ExitToShell();
-
- OpenSpeechDialog();
- }
-
-
- //____________________________________________________________
-
- void OpenSpeechDialog( void )
- {
- DialogPtr theDialog;
- short theItem;
- Boolean allDone = false;
- Str255 theString;
- OSErr theError;
-
- theDialog = GetNewDialog( rSpeechDialog, nil, (WindowPtr)-1L );
- ShowWindow( theDialog );
- SetPort( theDialog );
-
- while ( allDone == false )
- {
- ModalDialog( nil, &theItem );
-
- switch ( theItem )
- {
- case kSpeakShortButton:
- GetIndString( theString, rStringList, kShortStrIndex );
- theError = SpeakString( theString );
- if ( theError != noErr )
- ExitToShell();
- break;
-
- case kSpeakLongButton:
- GetIndString( theString, rStringList, kLongStrIndex );
- theError = SpeakString( theString );
- if ( theError != noErr )
- ExitToShell();
- break;
-
- case kQuitButton:
- allDone = true;
- break;
- }
- }
-
- DisposeDialog( theDialog );
- }
-
-
- //____________________________________________________________
-
- Boolean IsSpeechAvailable( void )
- {
- OSErr theError;
- long theResult;
- Boolean speechAvail;
-
- theError = Gestalt( gestaltSpeechAttr, &theResult );
- if ( theError != noErr )
- ExitToShell();
-
- speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );
- if ( speechAvail > 0 )
- return ( true );
- else
- return ( false );
- }
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void )
- {
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0L );
- FlushEvents( everyEvent, 0 );
- InitCursor();
- }
-
-
-
-